package com.dev;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.fb.FileBrowserPage;
import com.log;
public class ConfirmRemoveEditorTab extends LinearLayout implements OnClickListener{
	WindowManager.LayoutParams wlp=new WindowManager.LayoutParams();
	MainActivity ma;
	View destination;
	LinearLayout titlebar;
	LinearLayout bottombar;
	IconViewClose close;
	TextView title;
	TextView msg;
	TextButton tbSave,tbDiscard,tbRemove;
    ConfirmRemoveEditorTab(MainActivity ma){
		super(ma);
		this.ma=ma;
		setOrientation(VERTICAL);
		setWillNotDraw(false);
		title=new TextView(ma);
		title.setTextColor(0xff000000);
		title.setTextSize(TypedValue.COMPLEX_UNIT_DIP,14);
		title.setGravity(Gravity.CENTER_VERTICAL);
		title.setPadding(9,0,0,0);
		title.setText("移除：");
		close=new IconViewClose(ma);
		close.setOnClickListener(this);
		titlebar=new LinearLayout(ma){
			public void onDraw(Canvas cvs){
				super.onDraw(cvs);
				Paint p=new Paint();
				p.setColor(FileBrowserPage.borderColor);
				cvs.drawRect(0,getHeight()-FileBrowserPage.borderWidth,getWidth(),getHeight(),p);
			}
		};
		titlebar.setWillNotDraw(false);
		titlebar.setOrientation(HORIZONTAL);
		titlebar.addView(title,new LayoutParams(0,-1,1));
		titlebar.addView(close);
		msg=new TextView(ma);
		msg.setTextSize(TypedValue.COMPLEX_UNIT_DIP,13);
		msg.setTypeface(Typeface.MONOSPACE);
		msg.setTextColor(0xff000000);
		msg.setPadding(10,0,0,0);
		tbSave=new TextButton(ma,"保存");
		tbSave.borderColor=FileBrowserPage.borderColor;
		tbSave.borderWidth=FileBrowserPage.borderWidth;
		tbSave.borderTop=true;
		tbSave.setOnClickListener(this);
		tbDiscard=new TextButton(ma,"放弃");
		tbDiscard.borderColor=FileBrowserPage.borderColor;
		tbDiscard.borderWidth=FileBrowserPage.borderWidth;
		tbDiscard.borderTop=true;
		tbDiscard.setOnClickListener(this);
		tbRemove=new TextButton(ma,"是");
		tbRemove.borderColor=FileBrowserPage.borderColor;
		tbRemove.borderWidth=FileBrowserPage.borderWidth;
		tbRemove.borderTop=true;
		tbRemove.setOnClickListener(this);
		LinearLayout.LayoutParams bottombar_bt_lp=new LinearLayout.LayoutParams(0,-1,1);
		bottombar=new LinearLayout(ma);
		bottombar.setOrientation(HORIZONTAL);
		bottombar.addView(tbSave,bottombar_bt_lp);
		bottombar.addView(tbDiscard,bottombar_bt_lp);
		bottombar.addView(tbRemove,bottombar_bt_lp);
		addView(titlebar,-1,(int)(30*ma.dp));
		addView(msg,-1,-2);
		addView(bottombar,-1,(int)(30*ma.dp));
	}
    void show(View destination){
		this.destination=destination;
		wlp.width=ma.wp*3/4;
		wlp.height=-2;
		if(destination instanceof JavaEditorTab){
			JavaEditorTab jet=(JavaEditorTab)destination;
			if(jet.canSave){
				msg.setText("文件尚未保存，是否立即保存？");
				tbSave.setVisibility(VISIBLE);
				tbDiscard.setVisibility(VISIBLE);
				tbRemove.setVisibility(GONE);
			}else{
				msg.setText("是否关闭标签页");
				tbSave.setVisibility(GONE);
				tbDiscard.setVisibility(GONE);
				tbRemove.setVisibility(VISIBLE);
			}
		}else{
			log.alert("Unexpected parameter:",destination.getClass().getCanonicalName());
		}
		ma.wm.addView(this,wlp);
	}
    void dismiss(){
		ma.wm.removeView(this);
	}
	@Override
	public void onClick(View view) {
		if(view==close){
			dismiss();
		}else if(view==tbRemove){
			ma.gui.removeTab(destination);
			ma.gui.saveAllTab();
			dismiss();
		}else if(view==tbDiscard){
			ma.gui.removeTab(destination);
			ma.gui.saveAllTab();
			dismiss();
		}else if(view==tbSave){
			ma.gui.onClick(ma.gui.ivSave);
			ma.gui.removeTab(destination);
			ma.gui.saveAllTab();
			dismiss();
		}
	}
	@Override
	protected void onDraw(Canvas canvas){
		Paint p=new Paint();
		p.setColor(FileBrowserPage.borderColor);
		p.setStyle(Paint.Style.FILL);
		canvas.drawColor(0xffffffff);
		canvas.drawRect(0,0,FileBrowserPage.borderWidth,getHeight(),p);
		canvas.drawRect(0,0,getWidth(),FileBrowserPage.borderWidth,p);
		canvas.drawRect(getWidth()-FileBrowserPage.borderWidth,0,getWidth(),getHeight(),p);
		canvas.drawRect(0,getHeight()-FileBrowserPage.borderWidth,getWidth(),getHeight(),p);
		super.onDraw(canvas);
	}
}
